package com.qdairlines.common;

import com.qdairlines.entity.exflightinform.AbnormalFlight;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by yanxiguo on 2017/9/21.
 */
@Component
public class RestClient {

    @Autowired
    private RestTemplate restTemplate;

    private String exFlightUrl="http://172.16.3.226:9090/InterfaceForWeb/flight/getAbnormalFlights?flightDate={flightDate}&flightNo={flightNo}";

    public List<AbnormalFlight> getFlightInfo(String flightDate,String flightNo){
        Map<String,String>map=new HashMap<String,String>();
        map.put("flightDate",flightDate);
        map.put("flightNo",flightNo);
        AbnormalFlight[] responseEntity=restTemplate.getForObject(exFlightUrl, AbnormalFlight[].class,map);
        if (responseEntity==null||responseEntity.length==0){
            throw new CustomException("未查询到相关航班");
        }
        List<AbnormalFlight> abnormalFlights= Arrays.asList(responseEntity);
        return abnormalFlights;
    }



}
